package Java241123;

import java.lang.reflect.Array;

class MyArray<T> {
    public Object[] objects = new Object[10];
    /*public MyArray(Class<T> clazz,int capacity){
        objects = (T[]) Array.newInstance(clazz,capacity);
    }*/
    public T getPos(int pos){
        return (T)objects[pos];
    }
    public void setVal(int pos,T val){
        objects[pos] = val;
    }
    public Object[] getArray(){
        return objects;
    }
}
class Test1 {
    public static void main(String[] args) {
        MyArray<Integer> myArray = new MyArray<Integer>();
        myArray.setVal(0, 121);
        myArray.setVal(1, 10);
        int val = myArray.getPos(1);
        System.out.println(val);
        MyArray<String> myArray2 = new MyArray<>();
        myArray2.setVal(0, "hello");
        myArray2.setVal(1, "xiaomei");
        String ret = myArray2.getPos(1);
        System.out.println(ret);
    }
}

